# (1) 序列化: 将 Python 对象(字典)转为 JSON 字符串：json.dumps()

# import json
# dict_01 = {
#     'title': "长沙文创",
#     "author": {
#         "name": "John Doe",
#         "age": 35,
#         "isVerified": True
#     },
#     "tags": ("json", "syntax", "example"),
#     "rating": 4.5,
#     "isPublished": False,
#     "comments": None,
# }
#
# json_str = json.dumps(dict_01,indent=4,ensure_ascii=False)
#
# print(json_str)

# (2) 反序列化: 将 JSON 字符串转为 Python 对象：json.loads()
# import json
# json_str = '{"name": "李四", "age": 25, "is_student": true}'
# python_dict = json.loads(json_str)
# print(python_dict)


import random
from faker import Faker

def generate_user():
    fake = Faker()

    user = {
        'id': fake.uuid4(),
        'name': fake.name(),
        'username': fake.user_name(),
        'email': fake.email(),
        'phone': fake.phone_number(),
        'address': {
            'street': fake.street_address(),
            'city': fake.city(),
            'state': fake.state(),
            'zipcode': fake.zipcode(),
            'country': fake.country()
        },
        'birth_date': fake.date_of_birth(minimum_age=18, maximum_age=90).strftime('%Y-%m-%d'),
        'registration_date': fake.date_this_decade().strftime('%Y-%m-%d'),
        'gender': random.choice(['Male', 'Female', 'Other']),
        'website': fake.url(),
        'company': fake.company(),
        'job': fake.job(),
        'credit_card': {
            'number': fake.credit_card_number(),
            'expire': fake.credit_card_expire(),
            'provider': fake.credit_card_provider()
        },
        'interests': [fake.word() for _ in range(random.randint(1, 5))]
    }

    return user


# 使用示例
if __name__ == '__main__':
    user_data = generate_user()
    print(user_data)